package com.dfiov.cloud.msmtools.service.business.impl;

import com.alibaba.fastjson.JSON;
import com.dfiov.cloud.msmtools.entity.vo.msmtools.OpUserAccountVo;
import com.dfiov.cloud.msmtools.mapper.dfadminMapper.OpUserAccountMapper;
import com.dfiov.cloud.msmtools.mapper.entity.msmtools.OpUserAccount;
import com.dfiov.cloud.msmtools.service.business.OpUserAccountService;
import com.pateo.qingcloud.framework.common.base.BaseRestResponse;
import com.pateo.qingcloud.framework.common.statusCode.CommonStatusCode;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

import static com.dfiov.cloud.msmtools.contant.Constants.Modification_Failed;
import static com.dfiov.cloud.msmtools.contant.Constants.Modification_Failed_MSG;


@Slf4j
@Service
public class OpUserAccountImpl implements OpUserAccountService {


    @Resource
    OpUserAccountMapper opUserAccountMapper;

    @Override
    public BaseRestResponse<OpUserAccount> getOpUserAccount(OpUserAccountVo opUserAccountVo) {
        OpUserAccount opUserAccount = opUserAccountMapper.getOpUserAccount(opUserAccountVo.getPhone(), opUserAccountVo.getUsername());
        log.info("getOpUser::OpUser::"+ JSON.toJSONString(opUserAccount));
        return new BaseRestResponse<>(CommonStatusCode.SUCCESS0.getCode(), CommonStatusCode.SUCCESS0.getDetail(), opUserAccount);
    }

    @Override
    public BaseRestResponse<String> updateOpUserAccountLockStatus(String accountName) {
        long count = opUserAccountMapper.updateOpUserAccountLockStatus(accountName);
        if (count == 0) {
            return new BaseRestResponse<>(Modification_Failed, Modification_Failed_MSG, null);
        }else {
            log.info("updateOpUserAccountLockStatus::userName::"+ accountName+" success");
            return new BaseRestResponse<>(CommonStatusCode.SUCCESS0.getCode(), CommonStatusCode.SUCCESS0.getDetail(), accountName);
        }
    }




}
